package com.hx.voice.recognition.auth.server.util.user;

import com.hx.voice.recognition.auth.server.configuration.KeyConfiguration;
import com.hx.zjb.security.auth.common.util.jwt.IJWTInfo;
import com.hx.zjb.security.auth.common.util.jwt.JWTHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @descripe：
 * @company：南京华讯方舟通讯设备有限公司
 * @author：zhoujinbing
 * @time：2019/6/14 14:20
 * @version：V1.0
 */
@Configuration
public class JwtTokenUtil{

    /**
     * 用户过期时间
     */
    @Value("${jwt.expire}")
    private int expire;

    @Autowired
    private KeyConfiguration keyConfiguration;

    /**
     * @description 生成用户token
     * @method  generateToken
     * @param  [info]
     * @return java.lang.String
     * @date: 2019/6/14 14:23
     * @author:zhoujinbing
     */
    public String generateToken(IJWTInfo info) throws Exception {
        return JWTHelper.generateToken(info,keyConfiguration.getUserPriKey(),expire);
    }

    /**
     * @description 根据用户token获取用户信息
     * @method  getInfoFromToken
     * @param  [token]
     * @return java.lang.String
     * @date: 2019/6/14 14:23
     * @author:zhoujinbing
     */
    public IJWTInfo getInfoFromToken(String token) throws Exception {
        return JWTHelper.getInfoFormToken(token,keyConfiguration.getUserPubKey());
    }
}